<?php
/**
 * Created by PhpStorm.
 * User: king
 * Date: 2016/9/28
 * Time: 14:36
 */

namespace App\Util;

class LayUiVo
{

    public $code = 0;

    public $count = 0;

    public $message = '';

    public $jump = '';

    public $data = [];

    public function __construct($data = [], $allow = [], $expect = [])
    {

        $this->code = isset($data['code']) ? intval($data['code']) : 0;
        $this->count = isset($data['total']) ? intval($data['total']) : 0;
        $this->message = isset($data['message']) ? $data['message'] : '';
        $this->jump = isset($data['jump']) ? $data['jump'] : '';

        if ($this->code) {
            unset($this->data, $this->count);
        } else {

            if (isset($data['data']['total'])) {
                $this->count = $data['data']['total'];
                $this->data = $data['data']['results'];
            } else {
                unset($this->count);
                if (isset($data['data'])) {
                    $this->data = $data['data'];
                }
            }
            if (count($allow) || count($expect)) {
                if (count($this->data)) {
                    $this->data = Helper::arrayField($this->data, $allow, $expect);
                }
            }
        }

    }

}